package com.ssii.www.myproject.repository;

import com.ssii.www.myproject.domain.Permission;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface PermissionRepository extends  BaseRepository<Permission,Long>{


  @Query("select p from User u left join  u.roles r left join r.permissions p where u.id=?1")
  List<Permission> findPermissionsById(Long id);
  @Query("select p from Role r left join r.permissions p where r.id =?1")
  List<Permission> findPermissionsByRoleId(Long role_id);
  @Query(value = "select p.* from t_role r left join t_role_permission rp on r.id = rp.role_id left join t_permission p on rp.permission_id = p.id where (r.id=?1 or ?1 is null) limit ?2,?3",nativeQuery = true)
  List<Permission> findPagePermissionsByRoleId(Long id ,int pageNumber ,int pageSize);

}
